<template>
	<view class="container">
		<!-- 标题栏和状态栏占位符 -->
		<view class="titleNview-placing"></view>
		<!-- Top单品 -->
		<view class="seckill-section m-t top-goods" v-for="(a,index) in activityList" :key="index">
			<view class="s-header">
				<text class="title">{{a.sName||a.pName||a.name}}</text>
				<timeDown v-if="a.type == 1" :start="a.pStartDate" :end="a.pEndDate"></timeDown>

			</view>
			<scroll-view class="floor-list" scroll-x>
				<view class="scoll-wrapper">
					<view class="floor-item" v-for="(goods,index) in a.goodslist" :key="index"
						@click="toDetail(goods.pid,goods.iShopId)">
						<image :src="goods.defaultAlbum" mode="aspectFill" class="white-img"></image>
						<!-- <image class="ranking" :src="setRanking(index)" mode="aspectFill"></image> -->
						<!-- <text class="ranking">111</text> -->
						<text class="title clamp">{{goods.pName}}</text>
						<text class="price"><text class="unit">￥</text>{{goods.fSalePrice}}</text>
					</view>
					<view class="wrappe-item-box floor-item">
						<text class="look-more" @click="seckill(a)">查看更多&gt;</text>
					</view>
				</view>
			</scroll-view>
		</view>

		<!-- 猜你喜欢 -->
		<view class="f-header m-t">
			<view class="tit-box">
				<text class="line"></text>
				<text class="tit">热销产品</text>
				<text class="line"></text>
			</view>
		</view>
		<view class="list">
			<view class="guess-section ">
				<view class="guess-item" v-for="l in list" :key="l.id" @click="toDetail(l.goods.id,l.goods.iShopId)" v-if="l.goods">
					<view class="image-wrapper">
						<image :src="l.goods.fullDefaultImageUrl||''" mode="aspectFill"></image>
					</view>
					<view class="text">
						<text class="title clamp">{{l.goods.cName}}</text>
						<text class="price">
							<text class="unit">￥</text>{{l.goods.fSalePrice}}
							<text class="pay">{{l.goods.iSales}}人已付款</text>
							<image class="collect" src="/static/img/2/2-13.png" mode="aspectFill"></image>
						</text>
					</view>

				</view>


			</view>
		</view>

	</view>
</template>

<script>
	import timeDown from "./timeDown.vue"
	export default {
		data() {
			return {
				hours: 0,
				minutes: 0,
				seconds: 0,
				timer: null,
				page: 1,
				pages: 1,
				activityList: [],
				list: [{
					goods: {
						fullDefaultImageUrl: ''
					}
				}],
				promotionList: []
			};
		},
		components: {
			timeDown
		},
		onShow() {},
		props: ["shop_id"],
		mounted() {
			// this.timeDown()
			for (var i = 1; i < 15; i++) {
				if(i!=9){
					this.getActive(i)
				}
				
			}

			this.$Request.post4(
				this.$api.httpApi.home.shopHotGoods, {
					"shop_id": this.shop_id,
					page: this.pages,
					limit: 15
				}
			).then(res => {
				if (res.code == 1) {
					this.list = res.data.data
					this.list.forEach(item => {
						this.getGood(item)
					})
				}
			})
		},

		methods: {

			getActive(type) {
				 
				
				this.$Request.post4(
					
					this.$api.httpApi.promotion.getPricePreferentialList, {
						type: type,
						iShopId: this.shop_id
						
					}
				).then(res => {
					if (res.code == 200) {
						// this.activityList.push(res.data.data) 
						if (res.data.data.length > 0) {
							res.data.data.forEach(item => {
								this.getsrc(item, type)
							})

						}


					}
				})
				// this.activityList.forEach(item=>{
				// 	if(res.data.data.length>0){
				// 		this.getGoods(item)
				// 	}

				// })

			},


			getsrc(a, type) {
				
				this.$set(a, "type", type)

				var arr = []
				var re = /src="([^"]*)"/g;

				console.log(a.cDescription)
				if (a.cDescription != undefined) {
					while (arr = re.exec(a.cDescription)) {

						this.$set(a, "image", arr[1])
					}
				} else {
					this.$set(a, "image", '')
				}



				


				this.activityList.push(a)
				this.activityList.forEach(item => {
					this.getGoods(item)
				})
			},
			getGood(item) {
				this.$Request.get(this.$api.httpApi.goods.iteminfo + '&id=' + item.goods_id + '&token=' + this.$SysCache
					.get('token')).then(
					res => {
						if (res.code == 200) {
							this.$set(item, 'goods', res.data)
						}
					})
			},
			getGoods(item) {
				console.log(item)
				let type = ''
				if (item.type == 1) {
					//秒杀
					type = "PP"
				} else if (item.type == 2) {
					//团购
					type = "GB"
				} else if (item.type == 3) {
					//买赠
					type = "GP"
				} else if (item.type == 4) {
					//商品促销
					type = "PP"
				} else if (item.type == 5) {
					//整单促销
					type = "TP"
				}else if (item.type == 6) {
					//搭配销售
					type = "CP"
				} else if (item.type == 7) {
					//固定套餐
					type = "CP"
				} else if (item.type == 14) {
					//选配套餐
					type = "CP"
				} else if (item.type == 10) {
					//加价购
					type = "GP"
				} else if (item.type == 11) {
					//积分换购
					type = "HP"
				} else if (item.type == 12) {
					//N件购
					type = "TP"
				} else if (item.type == 13) {
					//N件购
					type = "AB"
				}
				this.$Request.post(
					this.$api.httpApi.search.search + "&token=" + this.$SysCache.get('token'), {
						queryCondition: {
							order: {
								fieldname: "iOrder",
								direction: "asc"
							},
							pageindex: 1,
							pagesize: 5,
							where: [{
								fieldname: "promotionActivityId",
								valuefrom: type + item.id
							}, {
								fieldname: "shop_id",
								valuefrom: this.shop_id
							}]
						},
						stopMessage:true
					}
				).then(res => {
					if (res.code == 200) {
						this.$set(item, "goodslist", res.data.data)
					}
				})



			},

			toDetail(id,shop_id) {
				// console.log(id)
				uni.navigateTo({
					url: `/pages/detail/index?id=${id}&iShopId=${shop_id}`
				})
			},
			seckill(item) {
				let type = item.type
				this.$SysCache.put('itemData', item, 864000)
				var cUrl = ''
				switch (type) {
					case 1:
						cUrl = `/pages/inner/seckill?id=${this.shop_id}`
						break;
					case 2:
						cUrl = `/pages/promotion/assemble/fresh?type=GB&id=${this.shop_id}`
						break;
					case 3:
						cUrl = `/pages/promotion/gifts/fresh?id=${this.shop_id}`
						break;
					case 4:
						cUrl = `/pages/promotion/index/index?id=${this.shop_id}`
						break;
					case 5:
						cUrl = `/pages/promotion/FullRreduction/fresh?id=${this.shop_id}`
						break;
					case 6:
						cUrl = `/pages/promotion/index/collocation?id=${this.shop_id}`
						break;
					case 7:
						cUrl = `/pages/promotion/index/collocation?id=${this.shop_id}&type=7`
						break;
					case 10:
						cUrl = `/pages/promotion/addmoney/fresh?id=${this.shop_id}`
						break;
					case 11:
						cUrl = `/pages/promotion/integral/fresh?id=${this.shop_id}`
						break;
					case 12:
						cUrl = `/pages/promotion/N_buy/index?id=${this.shop_id}`
						break;
					case 13:
						cUrl = `/pages/promotion/assemble/fresh?type=AB&id=${this.shop_id}`
						break;
					case 14:
						cUrl = `/pages/promotion/index/collocation?id=${this.shop_id}&type=14`
						break;
				}
				uni.navigateTo({
					url: cUrl
				})


			}
		}

	}
</script>

<style lang="less" scoped>
	.container {
		height: 100%;
		background-color: #EBEBEB;

		.f-header {
			display: flex;
			align-items: center;
			// height: 140upx;
			padding: 48upx 30upx 24upx;
			margin-top: 100upx;

			.tit-box {
				flex: 1;
				display: flex;
				// flex-direction: column;
				justify-content: center;
				align-items: center;

				.tit {
					display: inline-block;
					font-size: 27upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(51, 51, 51, 1);
					margin: 0 10upx;
				}

				.line {
					display: inline-block;
					width: 52upx;
					height: 2upx;
					background: rgba(102, 102, 102, 1)
				}
			}


		}

		.titleNview-placing {
			height: var(--status-bar-height);
			padding-top: 420upx;
			box-sizing: content-box;
		}

		.list {
			background-color: #ebebeb;
			width: 100%;
			position: relative;
			z-index: 10;
			padding-top: 20rpx;

			.guess-section {
				display: flex;
				flex-wrap: wrap;
				padding: 0 30upx;


				.guess-item {
					display: flex;
					flex-direction: column;
					width: 48%;
					padding-bottom: 29upx;
					background: #fff;
					margin-bottom: 21upx;

					&:nth-child(2n+1) {
						margin-right: 21upx;
					}

				}

				.image-wrapper {
					width: 100%;
					height: 330upx;
					border-radius: 3px;
					overflow: hidden;
					background: #fff;

					image {
						width: 100%;
						height: 100%;
						opacity: 1;
					}
				}

				.title {
					font-size: 23upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(68, 68, 68, 1);
					line-height: 35upx;
					padding-left: 30upx;
					padding-right: 30upx;
				}



				.price {
					font-size: 26upx;
					display: block;
					font-family: Adobe Heiti Std;
					font-weight: normal;
					color: rgba(240, 64, 111, 1);
					padding-left: 30upx;
					position: relative;

					.pay {
						font-size: 17upx;
						font-family: Microsoft YaHei;
						font-weight: 400;
						color: rgba(153, 153, 153, 1);
						margin-left: 6upx;
					}

					.collect {
						position: absolute;
						right: 29upx;
						bottom: 10upx;
						width: 30upx;
						height: 28upx;
						z-index: 1;
					}

				}


			}


		}

		/* 今日优选 */
		.seckill-section {
			padding: 4upx 30upx 24upx;
			position: relative;
			z-index: 10;
			background-color: #fff;
			margin-bottom: 10rpx;

			// background: #fff;
			.s-header {
				display: flex;
				align-items: center;
				height: 92upx;
				line-height: 1;

				.kk {
					display: inline-block;
					vertical-align: middle;
					width: 36rpx;
					height: 36rpx;
					background: #F04070;
					border-radius: 5rpx;
					text-align: center;
					line-height: 36rpx;
					font-size: 24rpx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: #FFFFFF;
				}

				.o {
					display: inline-block;
					vertical-align: middle;
					margin-left: 5rpx;
					margin-right: 5rpx;
					font-size: 24rpx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: #333333;
				}

				.title {
					font-size: 30upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(51, 51, 51, 1);
					margin-right: 10rpx;
				}

			}

			.floor-list {
				white-space: nowrap;
			}

			.scoll-wrapper {
				display: flex;
				align-items: flex-start;
			}

			.floor-item {
				margin-right: 26upx;
				font-size: 22upx;
				color: #444444;
				width: 250upx;
				line-height: 1.8;
				border-radius: 6upx;
				position: relative;

				.bac-index {
					height: 250upx;
					width: 250upx;
				}

				.look-more {
					display: flex;
					justify-content: center;
					align-items: center;
					height: 250upx;
					width: 250upx;
					background: #f0f0f0;
					box-shadow: 0px 0px 16px 0px rgba(0, 0, 0, 0.08);
					color: #666;
				}

				.white-img {
					height: 250upx;
					width: 250upx;
					background: rgba(255, 255, 255, 1);
					box-shadow: 0px 0px 16px 0px rgba(0, 0, 0, 0.08);

				}

				.title {
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(68, 68, 68, 1);
					font-size: 26upx;
				}

				.price {
					font-size: 26upx;
					font-family: Adobe Heiti Std;
					font-weight: normal;
					color: rgba(240, 64, 111, 1);
				}

				.new {
					position: absolute;
					top: 0;
					left: 0;
					width: 98upx;
					height: 32upx;
					background: rgba(77, 200, 151, 1);
					font-size: 17upx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: rgba(255, 255, 255, 1);
					text-align: center;
					line-height: 32upx;
				}

				.ranking {
					position: absolute;
					top: 24upx;
					left: 13upx;
					width: 43upx;
					height: 43upx;
					background: rgb(206, 167, 109) !important;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #fff;
					border-radius: 50%;

				}

			}
		}


	}
</style>
